# $Id: PKGBUILD 184406 2013-05-06 19:38:28Z foutrelis $
# Maintainer: Jan de Groot <jgc@archlinux.org>
# Contributor: dorphell <dorphell@archlinux.org>
# Contributor: Travis Willard <travis@archlinux.org>
# Contributor: Douglas Soares de Andrade <douglas@archlinux.org>

pkgname=libpng
pkgver=1.6.2
_apngver=1.6.2
pkgrel=3
pkgdesc="A collection of routines used to create PNG format graphics files"
arch=('i686' 'x86_64')
url="http://www.libpng.org/pub/png/libpng.html"
license=('custom')
depends=('zlib' 'sh')
options=('!libtool')
source=("http://downloads.sourceforge.net/sourceforge/$pkgname/$pkgname-$pkgver.tar.xz"
        "http://downloads.sourceforge.net/sourceforge/libpng-apng/libpng-$_apngver-apng.patch.gz"
        0001-libpng16-Avoid-dereferencing-NULL-pointer-possibly-r.patch
        0002-libpng16-Calculate-our-own-zlib-windowBits-when-deco.patch
        adjust-apng-patch-for-libpng16-git-changes.patch)
md5sums=('9d838f6fca9948a9f360a0cc1b516d5f'
         '7d0c9f4b9a7f45dd5d1088e54b623c98'
         '59b83234f60a7d1d179d9b0b6a0ebc01'
         'b1f7922b6678305bdb7c23d5bd1763f3'
         'f87704c3fb6d29f09b52178e89a42e2e')

prepare() {
  cd $pkgname-$pkgver

  # Add fixes from libpng16 branch
  patch -Np1 -i ../0001-libpng16-Avoid-dereferencing-NULL-pointer-possibly-r.patch
  patch -Np1 -i ../0002-libpng16-Calculate-our-own-zlib-windowBits-when-deco.patch

  # Add animated PNG (apng) support
  # see http://sourceforge.net/projects/libpng-apng/
  patch -d .. -Np0 -i adjust-apng-patch-for-libpng16-git-changes.patch
  patch -Np1 -i ../libpng-$_apngver-apng.patch
}

build() {
  cd $pkgname-$pkgver

  ./configure --prefix=/usr
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install

  cd contrib/pngminus
  make PNGLIB="-L$pkgdir/usr/lib -lpng" -f makefile.std png2pnm pnm2png
  install -m755 png2pnm pnm2png "$pkgdir/usr/bin/"
  install -D -m644 ../../LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
